package coreAlgorithm;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

public class NodeLookupSearchEntry {
	private final NodeTriple foundTriple;
	private boolean alreadyQueried = false;

	public NodeLookupSearchEntry(NodeTriple foundTriple) {
		super();
		this.foundTriple = foundTriple;
	}

	public NodeTriple getNodeTriple() {
		return foundTriple;
	}

	public boolean isAlreadyQueried() {
		return alreadyQueried;
	}

	public void setAlreadyQueried() {
		this.alreadyQueried = true;
	}

	public static ArrayList<NodeLookupSearchEntry> convertToNodeLookupList(List<NodeTriple> list) {
		ArrayList<NodeLookupSearchEntry> resultList = new ArrayList<NodeLookupSearchEntry>();
		for (Iterator<NodeTriple> iter = list.iterator(); iter.hasNext();) {
			resultList.add(new NodeLookupSearchEntry((NodeTriple) iter.next()));
		}
		return resultList;
	}

	public static Comparator<NodeLookupSearchEntry> NEAREST_TO_GIVEN_ID_COMPARATOR(final ID demandedID) {
		return new Comparator<NodeLookupSearchEntry>() {
			@Override
			public int compare(NodeLookupSearchEntry o1, NodeLookupSearchEntry o2) {
				return NodeTriple.NEAREST_TO_GIVEN_ID_COMPARATOR(demandedID).compare(o1.getNodeTriple(), o2.getNodeTriple());
			}
		};
	}

	@Override
	public boolean equals(Object obj) {
		return foundTriple.equals(((NodeLookupSearchEntry) obj).getNodeTriple());
	}

	@Override
	public int hashCode() {
		return foundTriple.hashCode();
	}
	
	@Override
	public String toString() {
		return "[" + foundTriple.toString() + "; Queried: " + alreadyQueried + "]";
	}

	// public static ArrayList<NodeTriple> convertToNodeTripleList(ArrayList<NodeLookupSearchEntry> list) {
	//
	// }
}
